package com.snowflake.ecatalog.entity;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.snowflake.ecatalog.contant.Status;

/**
 * 企业分类
 */
// JPA标识
@Entity
@Table(name = "t_ec_ccategory")
public class CompanyCategory extends OpEntity {

	private CompanyCategoryStandard std;
	private int sequence;
	private String number;
	private String name;
	private String remark;
	private int status;
	private List<Company> companys;

	public CompanyCategory() {
		super();
	}

	public CompanyCategory(Long id) {
		super();
		this.id = id;
	}

	@ManyToMany(cascade = CascadeType.REFRESH, mappedBy = "companyCategorys", fetch = FetchType.LAZY)
	public List<Company> getCompanys() {
		return companys;
	}

	public void setCompanys(List<Company> companys) {
		this.companys = companys;
	}

	// JPA 基于std_id列的多对一关系定义
	@ManyToOne
	@JoinColumn(name = "std_id")
	@JsonIgnore
	public CompanyCategoryStandard getStd() {
		return std;
	}

	public void setStd(CompanyCategoryStandard std) {
		this.std = std;
	}

	public int getSequence() {
		return sequence;
	}

	public void setSequence(int sequence) {
		this.sequence = sequence;
	}

	public String getNumber() {
		return number;
	}

	public void setNumber(String number) {
		this.number = number;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	// 不持久化到数据库
	@Transient
	public String getStatusName() {
		return Status.alias(this.status);
	}
}
